<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle"
               @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="accountColumns"
      :fetchapi="fetchApi"
      :params="accountParams"
      :isSelectColumn="false"
      :datakey="'records'"
      :isExportExcel2="true"
      :onRowSelectChange="selectChange"
      :onColumnsChange="columns => this.accountColumns = columns"
    >
    </FilterTable>

    <!-- <BaseDialog
      :visible.sync="issearch"
      :title="'服务站查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher @close="dealercloseHandler" />
    </BaseDialog> -->
    <BaseDialog title="服务站查询" :visible.sync="isShowSearchCustomer" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <SearchCustomer :customerNo="kehuxuanze" @close="isShowSearchCustomer = false" @addCustomerCode="confirmSearchCustomer" />
    </BaseDialog>
  </div>
</template>

<script>
  import { getOrderAccount } from '@/api/partsmanage/purchaseManage/purchaseSubmit';
  // import {ddlxArr, ddztArr, ddtblxArr} from './constant';
  // import PartOrderDetail from './partOrderDetail';
  import { dictionary } from '@/utils/dictMixin';
  // import { getCurrentUser } from '@/api/cms-api/origin/construct/dealer';
  import ownerSeacher from '@/pages/partsmanage/claim/approve/ownerSeacher';
  import SearchCustomer from '@/pages/partsmanage/purchaseManage/aduitOrderBusiness/SearchCustomer';

  export default {
    name: "OEMQuery",
    mixins: [ dictionary ],
    components: { ownerSeacher, SearchCustomer },
    data() {
      return {
        issearch: false,
        topFilterList: this.createTopFilterList(),
        accountColumns: this.createTableColumns(),
        fetchApi: getOrderAccount,
        pageType: 'OEM2', //查询页面类型DLR1：经销商采购提报页面 ，DLR2：经销商采购查询， OEM1：总部代提报页面， OEM2：总部采购查询
        fetchParams: { xhrAbort: true },
        handleType: '',
        rowSelectData: [],
        kehuxuanze: '',
        isShowSearchCustomer: false
      };
    },
    computed: {
      accountParams() {
        return {
          pageType: this.pageType,
          ...this.fetchParams
        }
      }
    },
    // async created() {
    //   this.columns.find(x => x.dataIndex === 'xsddsx').hidden = true;
    //   this.columns.find(x => x.dataIndex === 'xsddsx').dictItems = this.createDictList('5000');
    //   // 获取当前登录人信息
    //   await getCurrentUser({}).then(response => {
    //     console.info(response);
    //     if (response.data.appId === 'beijing') {
    //       console.info(this.topFilterList);
    //       this.topFilterList.find(x => x.fieldName === 'xsddsx').hidden = false;
    //       this.columns.find(x => x.dataIndex === 'xsddsx').hidden = false;
    //     }
    //   });
    // },
    methods: {
      createTopFilterList() {
        return [
          // {
          //   type: 'INPUT',
          //   label: '服务站代码',
          //   fieldName: 'dealerCodeQ',
          //   placeholder: '输入代码/名称',
          //   initialValue: '',
          //   unitRender: () => {
          //     return (
          //       <div>
          //         <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
          //       </div>
          //     );
          //   }
          // },
          { type: 'INPUT', label: '服务站代码', fieldName: 'dealerCode',
            unitRender: () => {
              return (
                <el-button icon="el-icon-search" onClick={() => { this.isShowSearchCustomer = true; }}></el-button>
              );
            },
            onEnter: val => {
              console.log('对方经销商 onEnter');
              this.isShowSearchCustomer = true;
            }
          },
          { type: 'INPUT', label: '服务站名称', fieldName: 'dealerName' },
          { type: 'INPUT', label: '采购单号', fieldName: 'xsddhm' },
          { type: 'INPUT', label: '销售单号', fieldName: 'sapdh' },
          { type: 'INPUT', label: '备件代码', fieldName: 'bjxmbh' },
          { type: 'INPUT', label: '备件名称', fieldName: 'bjzwmc' },
          { type: 'INPUT', label: '发运单号', fieldName: 'bsysdh' },
          { type: 'RANGE_DATE', label: '发运日期', fieldName: 'createdAt1|createdAt2', valueFormat: 'yyyy-MM-dd', placeholder: '请选择' },
          { type: 'SELECT', label: '订单状态', fieldName: 'xsddzt', itemList: this.createDictList('3002'), placeholder: '请选择' },
          { type: 'SELECT', label: '发运状态', fieldName: 'xsdjzt', itemList: this.createDictList('3014'), placeholder: '请选择' } 
        ]
      },
      createTableColumns() {
        return [
          {
            title: '序号',
            dataIndex: 'index',
            width: 70,
            sorter: true,
            render: props => {
              return <span>{props.row.index + 1}</span>;
            }
          },
          { title: '服务站代码', dataIndex: 'dealerCode', sorter: true },
          { title: '服务站名称', dataIndex: 'dealerName', sorter: true },
          { title: '采购单号', dataIndex: 'xsddhm', width: 150, sorter: true },
          { title: '销售单号', dataIndex: 'sapdh', width: 150, sorter: true },
          { title: '交货单号', dataIndex: 'bsysdh',  width: 150, sorter: true },
          { title: '订单状态', dataIndex: 'xsddzt', dictItems: this.createDictList('3002'), sorter: true },
          { title: '发运状态', dataIndex: 'xsdjzt', dictItems: this.createDictList('3014'), sorter: true },
          { title: '备件代码', dataIndex: 'bjxmbh', sorter: true },
          { title: '备件名称', dataIndex: 'bjzwmc', sorter: true },
          { title: '采购数量', dataIndex: 'bstxsl', sorter: true },
          { title: '采购单价', dataIndex: 'jjhdj', sorter: true },
          { title: '采购金额', dataIndex: 'xsysje', sorter: true },
          { title: '受理数量', dataIndex: 'bjfysl', sorter: true },
          { title: '签收数量', dataIndex: 'bjddsl', sorter: true },
          { title: '未受理数量', dataIndex: 'wslsl', sorter: true },
          { title: '关闭数量', dataIndex: 'bsbosl', sorter: true },
          { title: '是否闭环', dataIndex: 'boddzt', dictItems: this.createDictList('1004'), sorter: true },
          { title: '闭环人', dataIndex: 'boLoopName', sorter: true },
          { title: '闭环时间', dataIndex: 'boqrsj', sorter: true },
          { title: '提报人', dataIndex: 'submitByName', sorter: true },
          { title: '审核人', dataIndex: 'auditByName', sorter: true },
          { title: '发运日期', dataIndex: 'ddfysj', sorter: true },
          { title: '订单说明', dataIndex: 'remark', sorter: true },
        ]
      },
      selectChange(val) {
        this.rowSelectData = val;
      },
      changeHandle(val) {
        this.fetchParams = Object.assign({}, val);
      },
      collapseHandle() {
        this.$nextTick(() => {
          this.BaseTable.EXECUTE_RESET_HEIGHT();
        });
      },
      seacherFun() {
        this.issearch = true
      },
      // dealercloseHandler(val) {
      //   if(val) {
      //     this.topFilterList.find(x => x.fieldName == 'dealerCode').initialValue = val.dealerCode;
      //     this.topFilterList.find(x => x.fieldName == 'dealerName').initialValue = val.dealerName;
      //   }
      //   this.issearch = false;
      // }
      // dealercloseHandler(val, data) {
      //   if (data) {
      //     let dealerCodes = [];
      //     let dealerNames = [];
      //     data.map((x) => {
      //       dealerCodes.push(x.dealerCode);
      //       dealerNames.push(x.dealerName);
      //     });
      //     this.topFilterList.find((x) => x.fieldName == 'dealerCode').initialValue = dealerCodes.toString();
      //     this.topFilterList.find((x) => x.fieldName == 'dealerName').initialValue = dealerNames.toString();
      //   }
      //   this.issearch = false;
      // }
      async confirmSearchCustomer(row) {
        console.log(row, 'rowCustomer');
        this.rowData = row[0];
        console.log('row[0].dealerCode', row[0].dealerCode);
        this.topFilterList.find(x => x.fieldName == 'dealerCode').initialValue = row[0].dealerCode;
        this.topFilterList.find(x => x.fieldName == 'dealerName').initialValue = row[0].dealerName;
      }
    }
  }
</script>

<style scoped>

</style>
